package com.zhiliao.chain.demo2;


import java.io.Serializable;

/**
 * @author ：mengziquan
 * @date ：2020/8/3
 * @description ：结果集实体类
 */
public class BaseResultInfo<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 返回码:100:请求成功,200:入参错误,300:查询错误,400:回收单状态错误,500:核销码错误,600:图片不存在
     **/
    private Integer resultCode;

    /**
     * 返回内容
     **/
    private T data;

    /**
     * 返回描述
     **/
    private String errMsg;

    private boolean success;

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    @Override
    public String toString() {
        return "BaseResultInfo{" +
                "resultCode=" + resultCode +
                ", data=" + data +
                ", errMsg='" + errMsg + '\'' +
                '}';
    }

    public BaseResultInfo() {
    }

    public BaseResultInfo(Integer resultCode, String errMsg) {
        this.resultCode = resultCode;
        this.errMsg = errMsg;
    }

    public static <T>BaseResultInfo<T> getInstance(Integer code,T data){
        BaseResultInfo<T> baseResultInfo=new BaseResultInfo();
        baseResultInfo.setData(data);
        baseResultInfo.setResultCode(code);
        return baseResultInfo;
    }

    public static <T>BaseResultInfo<T> getInstance(Integer code,String message,T data){
        BaseResultInfo<T> baseResultInfo=new BaseResultInfo();
        baseResultInfo.setData(data);
        baseResultInfo.setErrMsg(message);
        baseResultInfo.setResultCode(code);
        return baseResultInfo;
    }

    public static <T>BaseResultInfo<T> getInstanceWithRecCode(RecResultCode responseCode, T data){
        BaseResultInfo<T> re = new BaseResultInfo(responseCode.getCode(),responseCode.getMsg());
        re.data=data;
        return re;
    }

}
